@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
    <!-- 配置文件 -->
    <script type="text/javascript" src="{{url('vendor/ueditor/ueditor.config.js')}}"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="{{url('vendor/ueditor/ueditor.all.js')}}"></script>
    @endsection

    @section('html-body')
            <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Index.packagesList')}}">套餐管理</a>
            <em>></em>
            <a >@if($package && $package->id)修改套餐信息 @else 添加套餐信息 @endif</a>
        </div>
        <!-- cur-position end -->

        <div class="list-wrap">
            <h2 class="head">
                <span class="span1">套餐信息</span>
            </h2>

            <!-- list-text-box start -->
            <form id="addAdvertiserInfo">
                <div class="list-text-box">
                    <div class="fill-list">
                        <label class="fill-tit">套餐名称：</label>
                        <div class="fill-cont">
                            <input class="fill-ipt" type="text" placeholder="请输入套餐名称" name="name" id="name" value="@if($package){{$package->pak_name}}@endif" /><span id="namere" class="required">*</span>
                        </div>
                    </div>
                    <div class="fill-list">
                        <label class="fill-tit">主治科目：</label>
                        <div class="fill-cont">
                            <input class="fill-ipt" type="text" placeholder="请输入套餐主治科目" name="subject" id="subject" value="@if($package){{$package->pak_subject}}@endif" /><span id="subjectre" class="required">*</span>
                        </div>
                    </div>
                    <div class="fill-list">
                        <label class="fill-tit">套餐图片：</label>
                        <div class="fill-cont">
                            <a class="fill-file-box" href="javascript:;" id="inputImage"></a>
                            <input type="hidden" id="licence_id" name="photo" value="@if($package){{$package->pak_img}}@endif"/>
                            <span class="lx" id="licence_msg">@if($package && (int)$package->pak_img !== 0)<img width="40px" height="40px" src="{{route('Api.Image.Show',['id'=>$package->pak_img])}}"> @else上传JPG ,PNG ,BMP ,GIF等格式 @endif</span>
                        </div>
                    </div>
                    <div class="fill-list">
                        <label class="fill-tit">套餐费(单位:元)：</label>
                        <div class="fill-cont">
                            <input class="fill-ipt" type="text" placeholder="请输入套餐金额,保留小数点后两位" name="consult_fee" id="consult_fee" value="@if($package){{$package->consulting_fee}}@endif" /><span id="consult_feere" class="required">*</span>
                        </div>
                    </div>
                    <div class="fill-list">
                        <label class="fill-tit">预约费(单位:元)：</label>
                        <div class="fill-cont">
                            <input class="fill-ipt" type="text" placeholder="请输入预约费,保留小数点后两位" name="bespeak_fee" id="bespeak_fee" value="@if($package){{$package->bespeak_fee}}@endif" /><span id="bespeak_feere" class="required">*</span>
                        </div>
                    </div>
                    <div class="fill-list">
                        <label class="fill-tit">套餐简介：</label>
                        <div class="fill-cont">
                            <textarea class="fill-texta" placeholder="请输入简介" name="detail">@if($package){{$package->pak_detail}}@endif</textarea>
                        </div>
                    </div>

                    <div class="fill-list">
                        <label class="fill-tit">是否上架：</label>
                        <div class="fill-cont" style="margin-top: 5px">
                            <input type="radio" name="is_off" value="0" @if($package && (int)$package->is_off == 0 || !$package)checked @endif> 是
                            <input type="radio" name="is_off" value="1" @if($package && (int)$package->is_off == 1)checked @endif>否
                        </div>
                    </div>
                    <input type="hidden" id="id" name="id" value="@if($package){{$package->id}}@else 0 @endif" />
                    <div class="fill-list">
                        <label class="fill-tit">&nbsp;</label>
                        <div class="fill-cont">
                            <input class="fill-submit" type="button" value="提交" />
                        </div>
                    </div>
                </div>
            </form>
            <!-- list-text-box end -->
        </div>
    </div>
    <!-- content end -->
    <script>
        jQuery(function($) {
//            <!-- 实例化编辑器 -->
//            var ue = UE.getEditor('adtips',{
//                autoHeightEnabled: true,
//                initialFrameHeight:400,
//                toolbars: [
//                    ['fullscreen', 'source', 'undo','redo','|','fontsize','horizontal','|','simpleupload','removeformat'],
//                    ['bold', 'italic', 'underline', 'forecolor', 'backcolor','|','indent','|','justifyleft', 'justifyright', 'justifycenter', 'justifyjustify', '|', 'rowspacingtop', 'rowspacingbottom', 'lineheight','|','insertunorderedlist', 'insertorderedlist','|', 'imagenone','imageleft','imageright','imagecenter','|','link']
//                ]
//            });

            jQuery.ajaxSetup({
                case:false,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            var doc = document,
                    $doc = $(doc);

            $doc.on('click','.fill-submit',function(){
                var name    = $('#name').val();
                var subject = $('#subject').val();
                var consult_fee     = $('#consult_fee').val();

                if(name == '' || name.length < 1){
                    $('#namere').html('*必填')
                }else if(subject == '' || subject.length <1){
                    $('#subjectre').html('*必填')
                }else if(consult_fee == '' || consult_fee.value < 0.01){
                    $('#consult_feere').html('*必填')
                }
                else {
                    $.ajax({
                        type:"post",
                        url:'{{route('Api.YiLiao.addPackages')}}',
                        dataType:"json",
                        data:$('#addAdvertiserInfo').serialize(),
                        success:function(obj){
                            if(obj.level == "success"){
                                tusi(obj.message);
                                window.location.href="{{route('Admin.Index.packagesList')}}";
                            }
                        },
                        error:function(obj){
                            var datajson = obj.responseJSON;
                            tusi(datajson.message);
                        }
                    });
                }
            });

            //上传营业执照图片
            var uploader = new plupload.Uploader({
                runtimes: 'html5,flash,silverlight,html4',
                browse_button: 'inputImage',
                url: '{{route('Api.Upload.Image')}}',

                chunk_size: '20mb',
                filters: {
                    max_file_size: '10mb',
                    mime_types: [
                        {title: "Image files", extensions: "jpg,gif,png"}
                    ],
                    prevent_duplicates: false
                },
                multi_selection: true,
                unique_names: true,

                flash_swf_url: '{{ url('vendor/plupload-2.1.2/Moxie.swf') }}',
                silverlight_xap_url: '{{ url('vendor/plupload-2.1.2/Moxie.xap') }}',

                file_data_name: 'photo',
                headers: {
                    Accept: 'application/json'
                },

                multipart_params: {
                    _token: '{{ csrf_token() }}'
                },

                init: {
                    PostInit: function () {
                    },

                    FilesAdded: function (up, files) {
                        up.start();
                    },

                    BeforeUpload: function (up, file) {
                        up.settings.multipart_params.file_name = file.name;
                    },

                    UploadProgress: function (up, file) {

                    },

                    Error: function (up, err) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(err.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }

                        noty({
                            type: 'error',
                            text: err.message + ' ' + responseMessage,
                            timeout: 800
                        });
                    },

                    FileUploaded: function (up, file, info) {
                        var responseObj = '', responseMessage = '';
                        try {
                            responseObj = $.parseJSON(info.response);
                            responseMessage = responseObj.message;
                        } catch ($e) {

                        }
                        $('#licence_id').val(responseObj.data.id);
                        $('#licence_msg').html('<span style="color: green">上传成功,'+responseObj.data.img_name+'</span>');
                    }
                }
            });
            uploader.init();
        });
    </script>
@endsection